package com.ycz.sportplay.controller;

import com.alibaba.fastjson.JSON;
import com.ycz.sportplay.bean.User;
import com.ycz.sportplay.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description
 * @ClassName LoginController
 * @Author yanchengzhi
 * @date 2022.06.14 19:09
 */
@RestController
public class LoginController {

    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public String login(@RequestBody User user) {
        String flag = "error";
        User findUser = userService.getUserByMessage(user.getUsername(),user.getPassword());
        Map<String,Object> map = new HashMap<>();
        if(findUser != null) {
            flag = "ok";
        }
        map.put("flag",flag);
        map.put("user",findUser);
        String res = JSON.toJSONString(map);
        return res;
    }

}
